package com.example.hybridmobiledemo.module.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;

import com.example.hybridmobiledemo.MainActivity;
import com.example.hybridmobiledemo.R;

public class LoginActivity extends AppCompatActivity {

    private EditText loginName;
    private EditText loginPassword;
    private EditText loginUserID;
    private ImageView imageView;
    private Button btnLogin;
    private Switch hideShow;
    private CheckBox autoLogin;
    private CheckBox remember;
    private ImageView cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //隐藏或显示密码
        hideShow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    loginPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else {
                    loginPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
            }
        });
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                finish();
            }
        });
    }

    private void initView() {
        loginName = (EditText) findViewById(R.id.login_name);
        loginPassword = (EditText) findViewById(R.id.login_password);
        loginUserID = (EditText) findViewById(R.id.login_userID);
        imageView = (ImageView) findViewById(R.id.imageView);
        btnLogin = (Button) findViewById(R.id.btn_login);
        hideShow = (Switch) findViewById(R.id.hide_show);
        autoLogin = (CheckBox) findViewById(R.id.auto_login);
        remember = (CheckBox) findViewById(R.id.remember);
        cancel = (ImageView) findViewById(R.id.cancel);
    }
}